package com.deer.wms.base.system.web.zhBusiness.business;

import com.deer.wms.base.system.model.zh.ShelfFaultDescription;
import com.deer.wms.base.system.service.zh.ShelfFaultDescriptionService;
import com.deer.wms.common.core.controller.BaseController;
import com.deer.wms.common.core.domain.AjaxResult;
import com.deer.wms.common.core.page.TableDataInfo;
import com.deer.wms.common.utils.poi.ExcelUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 李帅辰
 * @date 2021/6/1 18:08
 */
@Controller
@RequestMapping("/fault")
@Slf4j
public class ShelfFaultDescriptionController extends BaseController {
    @Autowired
    private ShelfFaultDescriptionService shelfFaultDescriptionService;

    private String prefix = "fault";

    /**
     *跳转显示页面
     * @return
     */
    @RequiresPermissions("fault:view")
    @GetMapping
    public String fault()
    {
        return prefix + "/fault";
    }

    @RequiresPermissions("fault:findList")
    @PostMapping("/findList")
    @ResponseBody
    public TableDataInfo findList(ShelfFaultDescription shelfFaultDescription) {
        startPage();
        List<ShelfFaultDescription> list = shelfFaultDescriptionService.findShelfFaultDescriptionList(shelfFaultDescription);
        return getDataTable(list);
    }
    @PostMapping("/partExcel")
    @ResponseBody
    public AjaxResult partExcel(@RequestParam String ids) {
        List<ShelfFaultDescription> byIds=new ArrayList();
        String[] split = ids.split(",");
        for (String s:split
        ) {
            ShelfFaultDescription b=new ShelfFaultDescription ();
            b.setId(Integer.parseInt(s));
            List<ShelfFaultDescription> list = shelfFaultDescriptionService.findShelfFaultDescriptionList(b);
            for (ShelfFaultDescription bs:list
            ) {
                byIds.add(bs);
            }

        }
        // List<BillInSapDto> billInSapList = billInSapService.findBillInSapDtoList(billInSapCriteria);
        ExcelUtil<ShelfFaultDescription> util = new ExcelUtil<ShelfFaultDescription>(ShelfFaultDescription.class);
        return util.exportExcel(byIds, "缓存线故障报表");
    }
    @RequiresPermissions("fault:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ShelfFaultDescription shelfFaultDescription) {
        List<ShelfFaultDescription> list = shelfFaultDescriptionService.findShelfFaultDescriptionList(shelfFaultDescription);
        ExcelUtil<ShelfFaultDescription> util = new ExcelUtil<ShelfFaultDescription>(ShelfFaultDescription.class);
        return util.exportExcel(list, "缓存线故障报表");
    }

}
